{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 简介\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><div></div><div></div><div><strong>Installed Packages</strong><ul><li><span>YiJingFramework.Annotating, 5.0.1</span></li><li><span>YiJingFramework.PrimitiveTypes, 4.0.1</span></li></ul></div></div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#r \"nuget:YiJingFramework.Annotating\"\n",
    "#r \"nuget:YiJingFramework.PrimitiveTypes\"\n",
    "using System.Diagnostics;\n",
    "using System.Text.Json;\n",
    "using YiJingFramework.Annotating;\n",
    "using YiJingFramework.PrimitiveTypes;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "此包提供了一个泛用的注解仓库结构。所谓的注解，例如《周易》就是为卦和卦爻所作的注解。\n",
    "\n",
    "> 此仓库关注的是通用结构，如果只关注《周易》，可以使用 [YiJingFramework.Annotating.Zhouyi](https://yjfwk.yueyinqiu.top/Annotating.Zhouyi/) 。\n",
    "\n",
    "此包原来给出的结构相对复杂，有好多种可以作为 key 的类型，比如一整个卦、某几根爻。但是在 `4.0.0` 版本之后，只有字符串类型可以作为 key ，因此现在的结构是非常简单的。\n",
    "\n",
    "每个 `AnnotationStore` 应该对应一个 json 文件，其中包含一个 `string? Title` （对应的 json 文件中为 `n` ）、一个 `IList<string> Tags` （ `t` ）和一个 `IList<AnnotationGroup> Groups` （ `g` ）。其中每个 `AnnotationGroup` 又包含 `string? Title` （ `t` ）、 `string? Comment` （ `c` ）和 `IList<AnnotationEntry> Entries` （ `e` ）。而每个 `AnnotationEntry` 中又包含 `string? Target` （ `t` ）和 `string? Content` （ `c` ）。\n",
    "\n",
    "举例而言：\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"n\": \"Sample Store\",\n",
      "  \"t\": [\n",
      "    \"Tag1\",\n",
      "    \"Tag2\",\n",
      "    \"Tag3\"\n",
      "  ],\n",
      "  \"g\": [\n",
      "    {\n",
      "      \"t\": \"Gua Name\",\n",
      "      \"e\": [\n",
      "        {\n",
      "          \"t\": \"111\",\n",
      "          \"c\": \"Qian\"\n",
      "        },\n",
      "        {\n",
      "          \"t\": \"000\",\n",
      "          \"c\": \"Kun\"\n",
      "        }\n",
      "      ],\n",
      "      \"c\": \"Names of the Guas\"\n",
      "    }\n",
      "  ]\n",
      "}\n",
      "111\n"
     ]
    }
   ],
   "source": [
    "var store = new AnnotationStore()\n",
    "{\n",
    "    Title = \"Sample Store\"\n",
    "};\n",
    "\n",
    "store.Tags.Add(\"Tag1\");\n",
    "store.Tags.Add(\"Tag2\");\n",
    "store.Tags.Add(\"Tag3\");\n",
    "\n",
    "var qian = new Gua(Enumerable.Repeat(Yinyang.Yang, 3));\n",
    "var kun = new Gua(Enumerable.Repeat(Yinyang.Yin, 3));\n",
    "\n",
    "var namingGroup = store.AddGroup(title: \"Gua Name\", comment: \"Names of the Guas\");\n",
    "namingGroup.AddEntry(qian.ToString(), \"Qian\");\n",
    "namingGroup.AddEntry(kun.ToString(), \"Kun\");\n",
    "\n",
    "var options = new JsonSerializerOptions() { WriteIndented = true };\n",
    "var serialized = store.SerializeToJsonString(options);\n",
    "Console.WriteLine(serialized);\n",
    "\n",
    "var d = AnnotationStore.DeserializeFromJsonString(serialized);\n",
    "Debug.Assert(d is not null);\n",
    "Console.WriteLine(d.Groups.Single(x => x.Title == \"Gua Name\").Entries[0].Target); // 111"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "总之，这个包给出的是通用结构，没有具体关注的内容。除非是在自己制作一种新的注解仓库，一般情况下不会直接依赖此包。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "file_extension": ".cs",
   "mimetype": "text/x-csharp",
   "name": "python",
   "pygments_lexer": "csharp",
   "version": "3.12.2"
  },
  "polyglot_notebook": {
   "kernelInfo": {
    "defaultKernelName": "csharp",
    "items": [
     {
      "aliases": [],
      "name": "csharp"
     }
    ]
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
